﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using System.IO;

namespace WcfServer.Classes.Utility
{
    public static class SerializerHandler<T>
    {

        public static byte[] SerializeInput(T inp)
        {
            IFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            
            formatter.Serialize(stream, inp);
            stream.Close();
            
            return stream.ToArray();
        }
        public static T DeSerializeInput(byte[] inp)
        {
            IFormatter formatter = new BinaryFormatter();
            MemoryStream stream = new MemoryStream();
            stream.Write(inp, 0, inp.Length);
            stream.Position = 0;
            var o = formatter.Deserialize(stream);
            stream.Close();
            return (T)o;
        }
    }
}
